using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace CXDB
{
    /// <summary>
    /// Controller class for CX_CompanyBase
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class CxCompanyBaseController
    {
        // Preload our schema..
        CxCompanyBase thisSchemaLoad = new CxCompanyBase();
        private string userName = String.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}
					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}
				}
				return userName;
            }
        }
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public CxCompanyBaseCollection FetchAll()
        {
            CxCompanyBaseCollection coll = new CxCompanyBaseCollection();
            Query qry = new Query(CxCompanyBase.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public CxCompanyBaseCollection FetchByID(object CompanyID)
        {
            CxCompanyBaseCollection coll = new CxCompanyBaseCollection().Where("CompanyID", CompanyID).Load();
            return coll;
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public CxCompanyBaseCollection FetchByQuery(Query qry)
        {
            CxCompanyBaseCollection coll = new CxCompanyBaseCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object CompanyID)
        {
            return (CxCompanyBase.Delete(CompanyID) == 1);
        }
        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object CompanyID)
        {
            return (CxCompanyBase.Destroy(CompanyID) == 1);
        }
        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(string CompanyID,string CompanyName,string CompanyAddress,int? TradeID,int? ElectricID,string PersonCardID,int? DepID,int? Scores,string Credit,string Status,int? EnteringID,int? VerifierID,DateTime? InTime,Guid? Guid)
	    {
		    CxCompanyBase item = new CxCompanyBase();
		    
            item.CompanyID = CompanyID;
            
            item.CompanyName = CompanyName;
            
            item.CompanyAddress = CompanyAddress;
            
            item.TradeID = TradeID;
            
            item.ElectricID = ElectricID;
            
            item.PersonCardID = PersonCardID;
            
            item.DepID = DepID;
            
            item.Scores = Scores;
            
            item.Credit = Credit;
            
            item.Status = Status;
            
            item.EnteringID = EnteringID;
            
            item.VerifierID = VerifierID;
            
            item.InTime = InTime;
            
            item.Guid = Guid;
            
	    
		    item.Save(UserName);
	    }
    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(string CompanyID,string CompanyName,string CompanyAddress,int? TradeID,int? ElectricID,string PersonCardID,int? DepID,int? Scores,string Credit,string Status,int? EnteringID,int? VerifierID,DateTime? InTime,Guid? Guid)
	    {
		    CxCompanyBase item = new CxCompanyBase();
	        item.MarkOld();
	        item.IsLoaded = true;
		    
			item.CompanyID = CompanyID;
				
			item.CompanyName = CompanyName;
				
			item.CompanyAddress = CompanyAddress;
				
			item.TradeID = TradeID;
				
			item.ElectricID = ElectricID;
				
			item.PersonCardID = PersonCardID;
				
			item.DepID = DepID;
				
			item.Scores = Scores;
				
			item.Credit = Credit;
				
			item.Status = Status;
				
			item.EnteringID = EnteringID;
				
			item.VerifierID = VerifierID;
				
			item.InTime = InTime;
				
			item.Guid = Guid;
				
	        item.Save(UserName);
	    }
    }
}
